package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);
    /*新增菜品 xml映射   AutoFill自动填充时间 创建人等*/
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);
    /*/*菜品分页查询  xml映射*/
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);
    /*根据主键查*/
    @Select("select * from dish where id=#{id}")
    Dish getById(Long id);
    /*根据主键删除*/
    @Delete("delete from dish where id=#{id}")
    void deleteById(Long id);
    /*根据菜品id批量删除菜品数据*/
    void deleteByIds(List<Long> ids);
    /*根据菜品id动态修改菜品数据 xml映射*/
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);
    /*查找一个分类id下对应的多个菜品*/
    List<Dish> getBycategoryId(Dish dish);
    /*根据setmaelId查对应菜品*/
    @Select("select d.* from dish d left join setmeal_dish sd on d.id =sd.dish_id where sd.setmeal_id=#{setmealId}")
    List<Dish> getBysetmealId(Long setmealId);
     /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
